import fireAlarmVue from "@/components/fireAlarm/fireAlarm.vue";

// 定义插件对象
const fireAlarm = {};

fireAlarm.install= function (Vue, options){
    console.log(options)
    const fireAlarmInstance = Vue.extend(fireAlarmVue);
    let currentMsg;
    const initInstance = () => {
        // 实例化vue实例
        currentMsg = new fireAlarmInstance();
        let fireAlarmEl = currentMsg.$mount().$el;
        document.body.appendChild(fireAlarmEl);
    };

    Vue.prototype.$fireAlarm = {
        show (options) {
            if (!currentMsg) {
                initInstance();
            }
            console.log(currentMsg)
            if (typeof options === 'string') {
                currentMsg.content = options;
            } else if (typeof options === 'object') {
                Object.assign(currentMsg.fireInfo, options);
            }
            return currentMsg.show().then(val => {
                console.log(val)
                currentMsg = null;
                return Promise.resolve(val);
            }).catch(err => {
                console.log(err)
                currentMsg = null;
                return Promise.reject(err);
            });

        },
        close(){
            if (currentMsg){
                currentMsg.close()
            }
        }
    };



}

export default fireAlarm;